package  
{
	import org.flixel.FlxTilemap;
	import entities.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class ReflectionMap extends FlxTilemap
	{
		public var scene:GameScene;
		
		public var entityReplacements:Object = {
			17:function(x:int, y:int, scene:GameScene):void { scene.throwables.add(new BasicApple(x, y, scene)); },
			62:function(x:int, y:int, scene:GameScene):void { scene.endTrigger = new EndLevelTrigger(x, y, scene); },
			10:function(x:int, y:int, scene:GameScene):void { scene.collidableEntities.add(new QuestionBlock(x, y, scene)); },
			11:function(x:int, y:int, scene:GameScene):void { scene.collidableEntities.add(new DestroyBlock(x, y, scene)); },
			27:function(x:int, y:int, scene:GameScene):void { scene.collidableEntities.add(new Raft(x, y, scene)); },
			51:function(x:int, y:int, scene:GameScene):void { scene.enemies.add(new SlimeEnemy(x, y, scene)); },
			15:function(x:int, y:int, scene:GameScene):void { scene.collidableEntities.add(new PushBlock(x, y, scene)); }
		};
		
		public function ReflectionMap(scene:GameScene) 
		{
			super();
			this.scene = scene;
			this.cameras = [scene.camera];
		}
		
		override public function loadMap(MapData:String, TileGraphic:Class, TileWidth:uint = 0, TileHeight:uint = 0, AutoTile:uint = OFF, StartingIndex:uint = 0, DrawIndex:uint = 1, CollideIndex:uint = 1):FlxTilemap 
		{
			var ret:FlxTilemap = super.loadMap(MapData, TileGraphic, TileWidth, TileHeight, AutoTile, StartingIndex, DrawIndex, CollideIndex);
			replaceEntities();
			return ret;
		}
		
		public function replaceEntities():void
		{
			for (var x:int = 0; x < widthInTiles; x++)
			{
				for (var y:int = 0; y < heightInTiles; y++)
				{
					var tileNum:uint = getTile(x, y);
					if (entityReplacements[tileNum])
					{
						entityReplacements[tileNum](x * _tileWidth, y * _tileHeight, this.scene);
						setTile(x, y, 0, true);
					}
				}
			}
		}
		
	}

}